import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { PluginConfig } from '../model/plugin-config';
import { BasePlugin } from '../model/base-plugin';

@Injectable({
  providedIn: 'root'
})
export class PluginConfigService {

  constructor(
    private http: HttpClient
  ) { }

  getPlugins(pluginType: string): Observable<BasePlugin[]> {
    return this.http.get<BasePlugin[]>(`/plugins?pluginType=${pluginType}`);
  }

  install(pluginId: string): Observable<void> {
    return this.http.post<void>(`/plugins/${pluginId}/install`, null);
  }

  uninstall(pluginId: string): Observable<void> {
    return this.http.post<void>(`/plugins/${pluginId}/uninstall`, null);
  }

  update(data: PluginConfig): Observable<void> {
    return this.http.put<void>('/plugins', data);
  }
}
